<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>乡村团购</title>
<!-- Tell the browser to be responsive to screen width -->
<meta
	content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
	name="viewport">
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
<link rel="stylesheet" href="https://unpkg.com/bootstrap@3.3.7/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://unpkg.com/font-awesome@4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://unpkg.com/admin-lte@2.3.8/dist/css/AdminLTE.min.css">
<link rel="stylesheet" href="https://unpkg.com/admin-lte@2.3.8/dist/css/skins/_all-skins.min.css">
<link rel="stylesheet" href="/css/main.css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->
</head>
<body class="hold-transition login-page" style="background-image: linear-gradient(to right bottom , #aac9ff,#bce5f8);">
	<div class="login-box" id="app" v-cloak>
		<div class="login-logo">
			<b>乡村团购后台管理系统</b>
		</div>
		<!-- /.login-logo -->
		<div class="login-box-body">
			<p class="login-box-msg">管理员登录</p>
			<div v-if="error" class="alert alert-danger alert-dismissible">
				<h4 style="margin-bottom: 0px;">
					<i class="fa fa-exclamation-triangle"></i> {{errorMsg}}
				</h4>
			</div>
			<div class="form-group has-feedback">
				<input type="text" class="form-control" v-model="username"
					placeholder="账号"> <span
					class="glyphicon glyphicon-user form-control-feedback"></span>
			</div>
			<div class="form-group has-feedback">
				<input type="password" class="form-control" v-model="password"
					placeholder="密码"> <span
					class="glyphicon glyphicon-lock form-control-feedback"></span>
			</div>
			<div class="form-group has-feedback">
				<div class="row">
					<!-- /.col -->
					<div class="col-xs-8">
						<input type="text" class="form-control" v-model="captcha"
							@keyup.enter="login" placeholder="验证码">
					</div>
					<div class="col-xs-4">
						<img alt="如果看不清楚，请单击图片刷新！" class="pointer" :src="src"
							@click="refreshCode" style="width: 100%; height: 34px">
					</div>
				</div>
			</div>

			<div class="form-group has-feedback">
				<div class="row">
					<!-- /.col -->
					<div class="col-xs-12">
						<button type="button" class="btn btn-primary btn-block btn-flat"
							@click="login">登录</button>
					</div>
					<!-- /.col -->
				</div>
			</div>
			<!-- /.social-auth-links -->

		</div>
		<!-- /.login-box-body -->
	</div>
	<!-- /.login-box -->
	<script src="https://unpkg.com/jquery@2.2.4/dist/jquery.min.js"></script>
	<script src="https://unpkg.com/vue@2.2.6/dist/vue.min.js"></script>
	<script src="https://unpkg.com/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
	<script src="https://unpkg.com/admin-lte@2.3.8/dist/js/app.js"></script>
	<script src="/js/admin/components.js"></script>
	<script type="text/javascript">
var vm = new Vue({
	el:'#app',
	data:{
		username: 'admin',
		password: 'admin',
        captcha: '',
		error: false,
		errorMsg: '',
        src: '/captcha.jpg'
	},

	methods: {
        refreshCode: function(){
            this.src = "/captcha.jpg?t=" + $.now();
        },
		login: function () {
            var data = "username="+vm.username+"&password="+vm.password+"&captcha="+vm.captcha;
			$.ajax({
				type: "POST",
			    url: "/sys/login",
			    data: data,
			    dataType: "json",
			    success: function(r){
					if(r.code == 0){//登录成功
                        localStorage.setItem("token", r.token);
                        parent.location.href ='index.html';
					}else{
						vm.error = true;
						vm.errorMsg = r.msg;
                        vm.refreshCode();
					}
				}
			});
		}
	}
});
</script>
</body>
</html>
